package cond

import "clientDemo/service/cond"

const (
	Cond_Operate_Nil      cond.Operate_Type = 0 //无
	Cond_Operate_Count    cond.Operate_Type = 1 //计数
	Cond_Operate_Sum      cond.Operate_Type = 2 //求和
	Cond_Operate_Average  cond.Operate_Type = 3 //平均
	Cond_Operate_Max      cond.Operate_Type = 4 //最大
	Cond_Operate_Min      cond.Operate_Type = 5 //最小
	Cond_Operate_First    cond.Operate_Type = 6 //首次出现
	Cond_Operate_GetValue cond.Operate_Type = 7 //取值
)

func (m *CondModule) initOperate() {
	m.RegeditOperate(Cond_Operate_Count, func(condData cond.ICondRoleItem, score int64) int64 {
		num := condData.GetTimeCount()
		condData.AddTimeCount()
		return num + 1
	})
	m.RegeditOperate(Cond_Operate_Sum, func(condData cond.ICondRoleItem, score int64) int64 {
		num := condData.GetOperateScore()
		num += score
		condData.SetOperateScore(num)
		condData.AddTimeCount()
		return num
	})
	m.RegeditOperate(Cond_Operate_Average, func(condData cond.ICondRoleItem, score int64) int64 {
		num := condData.GetOperateScore()
		count := condData.GetTimeCount()
		num = (num*count + score) / (count + 1)
		condData.SetOperateScore(num)
		condData.AddTimeCount()
		return num
	})
	m.RegeditOperate(Cond_Operate_Max, func(condData cond.ICondRoleItem, score int64) int64 {
		num := condData.GetOperateScore()
		if score >= num {
			num = score
			condData.SetOperateScore(num)
		}
		condData.AddTimeCount()
		return num
	})
	m.RegeditOperate(Cond_Operate_Min, func(condData cond.ICondRoleItem, score int64) int64 {
		num := condData.GetOperateScore()
		if num == 0 || score <= num {
			num = score
			condData.SetOperateScore(num)
		}
		condData.AddTimeCount()
		return num
	})
	m.RegeditOperate(Cond_Operate_First, func(condData cond.ICondRoleItem, score int64) int64 {
		condData.AddTimeCount()
		count := condData.GetTimeCount()
		return count
	})
	m.RegeditOperate(Cond_Operate_GetValue, func(condData cond.ICondRoleItem, score int64) int64 {
		condData.AddTimeCount()
		return score
	})
}
